package com.block.api.controller.externalapi;

import cn.hutool.core.util.ObjectUtil;
import com.block.common.util.LocalDateUtil;
import com.block.datapush.service.IMemberPushOrderInfoService;
import com.block.db.entity.MemberExtInfo;
import com.block.db.entity.MemberPushOrderInfo;
import com.block.db.entity.SourcePushResultInfo;
import com.block.db.entity.SpecialCostomInfo;
import com.block.db.mapper.MemberExtInfoMapper;
import com.block.db.mapper.SpecialCostomInfoMapper;
import com.block.source.service.ISourcePushResultInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

/**
 * 用户授权协议书
 * 需要动态生成的协议书
 * 需要展示商户相关信息
 */
@Controller
@RequestMapping("page/user")
public class UserPageController {


    @Autowired
    IMemberPushOrderInfoService memberPushOrderInfoService;
    @Resource
    MemberExtInfoMapper memberExtInfoMapper;
    @Resource
    SpecialCostomInfoMapper specialCostomInfoMapper;
    @Autowired
    ISourcePushResultInfoService sourcePushResultInfoService;

    /**
     * 授权书
     *
     */
    @RequestMapping(value = "/newprotocol/{orderNo}.html")
    public String checkUser(@PathVariable("orderNo") String orderNo,
                            ModelMap modelMap){

//        SourcePushResultInfo sourcePushResultInfo = sourcePushResultInfoService.getById(orderNo);
//        if (ObjectUtil.isEmpty(sourcePushResultInfo) ){
//            modelMap.put("message", "查询不到数据订单");
//            return "error";
//        }

        MemberPushOrderInfo pushOrderInfo = memberPushOrderInfoService.getById(orderNo);
        if (ObjectUtil.isEmpty(pushOrderInfo) ){
            modelMap.put("message", "查询不到数据推送订单");
            return "error";
        }

        MemberExtInfo memberExtInfo = memberExtInfoMapper.selectById(pushOrderInfo.getUid());
        SpecialCostomInfo costomInfo = specialCostomInfoMapper.selectById(pushOrderInfo.getInfoId());


        modelMap.put("username", memberExtInfo.getUsername());
        modelMap.put("idCard", memberExtInfo.getIdCard());
        modelMap.put("uid", String.valueOf(memberExtInfo.getUid()));
        modelMap.put("dateTime", LocalDateUtil.getNowDateStrByTotalDataTime());

        modelMap.put("infoId", costomInfo.getId());
        modelMap.put("companyName", costomInfo.getCompanyName());

        return "newprotocol";
    }

}